package com.ln.dto;

import java.util.HashMap;

import com.ln.exception.DTOException;

public class ResultObj extends HashMap<String, Object> {
	private static final long serialVersionUID = -3251238073848073617L;
	public ResultObj() {
		super();
	}
	public ResultObj(int initialCapacity) {
		super(initialCapacity);
	}
	public Object set(Object key, Object value) {
		return super.put(key.toString(), value);
	}
	public ResultObj add(Object key, Object value) {
		super.put(key.toString(), value);
		return this;
	}
	public String getString(Object key) throws DTOException {
		Object o = super.get(key);
		return o == null ? null : o.toString();
	}

	public int getInt(Object key) throws DTOException {
		Object o = super.get(key);
		if (o == null || "".equals(o)) {
			throw new DTOException("ObjectMap[\"" + key + "\"] not found.");
		}
		return Integer.valueOf(o.toString());
	}

	public long getLong(Object key) throws DTOException {
		Object o = super.get(key);
		if (o == null || "".equals(o)) {
			throw new DTOException("ObjectMap[\"" + key + "\"] not found.");
		}
		return Long.valueOf(o.toString());
	}

	public boolean getBool(Object key) throws DTOException {
		Object o = super.get(key);
		if (o == null || "".equals(o)) {
			throw new DTOException("ObjectMap[\"" + key + "\"] not found.");
		}
		return Boolean.valueOf(o.toString());
	}
}
